package com.shizhanzhe.zxbapp.task;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.Share;
import com.shizhanzhe.zxbapp.bean.UserBean;
import com.shizhanzhe.zxbapp.url.Path;

import java.util.List;

/**
 * Created by zz9527 on 2018/10/19.
 */
public class ShareAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private Context mContext;
    private List<Share.DataBean> list;
    private int type;

    public ShareAdapter(List<Share.DataBean> list, Context context, int type) {
        this.list = list;
        this.mContext = context;
        this.type = type;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_lv_share, null);
            holder = new ViewHolder();
            holder.img = convertView.findViewById(R.id.share_img);
            holder.vip = convertView.findViewById(R.id.iv_isvip);
            holder.title = convertView.findViewById(R.id.tv_share_title);
            holder.all = convertView.findViewById(R.id.all);
            holder.all1 = convertView.findViewById(R.id.tv_share_all1);
            holder.all2 = convertView.findViewById(R.id.tv_share_all2);
            holder.tv = convertView.findViewById(R.id.tv);
            holder.one = convertView.findViewById(R.id.tv_share_one);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Share.DataBean bean = list.get(i);
        if (bean.getType() == 1) {
            holder.vip.setVisibility(View.VISIBLE);
        } else {
            holder.vip.setVisibility(View.GONE);
        }
        if (type == 1) {
            holder.tv.setText("  分享已获得");
//            if (UserBean.level > 0) {
//                holder.all.setText("+" + bean.getVipall() + "元");
//            } else {
//                holder.all.setText("+" + bean.getAll() + "元");
//            }
//            holder.all.setVisibility(View.VISIBLE);
//            holder.all1.setVisibility(View.GONE);
//            holder.all2.setVisibility(View.GONE);
            holder.one.setText(bean.getFen() + "元");
        } else {
            holder.one.setText(Html.fromHtml("<font color='#f12626'>"+bean.getOne()+"元</font>/<font color='#4d3af7'>"+bean.getVipone()+"元</font>"));

        }
        holder.all1.setText("普通赚" + bean.getAll() + "元");
        holder.all2.setText("VIP赚" + bean.getVipall() + "元");
        Glide.with(mContext).load(Path.img(bean.getImg())).into(holder.img);
        holder.title.setText(bean.getShname());
        return convertView;
    }

    private static class ViewHolder {
        ImageView img;
        ImageView vip;
        TextView title;
        TextView tv;
        TextView all;
        TextView all1;
        TextView all2;
        TextView one;
    }
}
